package echo

import (
	"encoding/json"
	"github.com/gin-gonic/gin"
	models "wx-uniapp-go/internal/repository/models"
	"wx-uniapp-go/utils"
)

const USERINFO_KEY = "global:context:userinfo"

func SetUserInfo(c *gin.Context, uInfo *models.User) {
	if uInfo != nil {
		uInfoStr := utils.StructToString(uInfo)
		c.Set(USERINFO_KEY, uInfoStr)
	}
}

func GetUserInfo(c *gin.Context) *models.User {
	uInfoStr := c.GetString(USERINFO_KEY)
	var uInfo *models.User
	_ = json.Unmarshal([]byte(uInfoStr), &uInfo)
	return uInfo
}
